package aqua.smile.springboot.security.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;

/**
 * 授权
 *
 * @author chujian
 * @since 2022-11-08 22:12
 **/
@Configuration
@EnableWebSecurity
public class MyWebSecurityConfig extends WebSecurityConfigurerAdapter {

    @Override
    protected void configure(HttpSecurity http) throws Exception {

        http.csrf().disable()
                .authorizeRequests()
                .antMatchers("/first/**").hasAuthority("admin")
                .antMatchers("/second/**").hasAnyAuthority("user", "admin")
                .antMatchers("/userInfo/**").permitAll()

                .anyRequest().authenticated()

                .and()
                .formLogin().loginPage("/login");

    }

    @Override
    protected void configure(AuthenticationManagerBuilder auth) throws Exception {

    }
}
